package com.dmcb.trade.business.utils;

import com.dmcb.common.business.utils.JsonUtil;
import com.dmcb.common.business.utils.WebClientUtil;
import com.gargoylesoftware.htmlunit.WebClient;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by miting on 2018/12/24
 */
public class NewsBaiDuCrawlUtil {

    public static Map<String, String> getInfo(String link) {
        Map<String, Object> map;
        Map<String, String> map1 = new HashMap<>();
        WebClientUtil webClientUtil = new WebClientUtil();
        WebClient webClient = webClientUtil.initWc(false, false, false);
        String data = webClientUtil.getDoc2(webClient, link).toString();
        data = data.substring(data.indexOf("news\":[") + 7);
        data = data.substring(0, data.indexOf("]}};"));
        map = JsonUtil.getResult(data);
        if (map==null || map.size()==0){
            return null;
        }
        //标题
        String title = (String) map.get("title");
        if (StringUtils.isBlank(title)){
            return null;
        }
        map1.put("title",title);
        return map1;
    }
}
